package api

import (
	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"task00/pkg/api/handler"
)

type ServerHTTP struct {
	engine *gin.Engine
}

func NewServerHTTP(userHandler *handler.Handler) *ServerHTTP {
	engine := gin.New()

	// Use logger from Gin
	engine.Use(gin.Logger())

	// Swagger docs
	// to build swagger for me :) C:\Users\suyd\go\bin\swag init  --parseDependency -g ./cmd/app/main.go
	engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

	//Account methods
	engine.POST("/registration", userHandler.Registration)
	engine.POST("/login", userHandler.Login)
	engine.PUT("/accounts/:accountId", userHandler.PutAccount)
	engine.GET("/accounts/:accountId", userHandler.GetAccount)
	engine.DELETE("/accounts/:accountId", userHandler.DeleteAccount)

	engine.POST("/region", userHandler.CreateRegion)
	engine.PUT("/region/:regionId", userHandler.UpdateRegion)
	engine.GET("/region/:regionId", userHandler.GetOsmData)
	engine.DELETE("/region/:regionId", userHandler.DeleteRegion)

	return &ServerHTTP{engine: engine}
}

func (sh *ServerHTTP) Start() {
	sh.engine.Run(":8001")
}
